thin.imports('/public/home/css/global.project.css');

thin.imports('/public/configure/conf.agency.js');

thin.use(function() {
	$.showLoading();
	factory.request('_agency_volist');

	$('#agency-volist').on('click', '#btn-des', function(e) {
		var agnid = $(this).attr('data-id');
		if(!agnid_opt[agnid]) {
			$.showLoading();
			__getdata_agencyget['id'] = agnid;
			factory.request('_agency_get');
		} else {
			binddata(agnid_opt[agnid]);
		}
	});
});

function __complete_agencyget(res) {
	$.hideLoading();
	if(res.status == 200) {
		agnid_opt[res.data.id] = res.data;
		binddata(res.data);
	} else {
		// nothing
	}
}

function binddata(data) {
	$('#bind-pd-logo').attr('src', data.logo);
	$('#bind-pd-title').text(data.title);
	$('#bind-pd-introduction').html('');
	var val = data.introduction;
	val = val.replace(/&lt;/gi, '<');
	testEditormdView = editormd.markdownToHTML("bind-pd-introduction", {
		markdown: val,
		htmlDecode: "style,script,iframe", // you can filter tags decode
		tocm: true, // Using [TOCM]
		emoji: true,
		taskList: true,
		tex: true, // 默认不解析
		flowChart: true, // 默认不解析
		sequenceDiagram: true, // 默认不解析
	});
	$("#details-template").popup();
}

function __complete_agencylist(res) {
	$.hideLoading();
	if(res.status == 200) {
		createVolist(res.data);
	} else {
		// nothing
	}
}

var agnid_opt = {},
	__getdata_agencyget = {};

function createVolist(data) {
	var ele = '';
	for(var i in data) {
		ele += '<div class="agency-boxs">';
		ele += '<a href="' + data[i].url + '" data-id="' + data[i].id + '" id="btn-des" class=" ag-bg' + (i % 4) + '" >';
		ele += '<div class="weui-grid__icon">';
		ele += '<img src="' + data[i].logo + '" alt="">';
		ele += '</div>';
		ele += '<p class="weui-grid__label">' + data[i].title + '</p>';
		ele += '</a>';
		ele += '</div>';
	}
	$('#agency-volist').html(ele);
}